import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

public class Test {
    public Queue<Integer> qu1=new LinkedList<>();;
    public Queue<Integer> qu2=new LinkedList<>();;



    public void push(int x) {
        if(empty()){
            qu1.offer(x);
        }else{
            if(qu1.isEmpty()){
                qu1.offer(x);
            }else{
                qu2.offer(x);
            }
        }

    }

    public int pop() {
        int tmp=0;

        if(qu1.isEmpty()){
            while(!qu2.isEmpty()){
            tmp=qu2.poll();
                qu1.offer(tmp);
            }

        }
        if(qu2.isEmpty()){
            while(!qu1.isEmpty()){
         tmp=qu1.poll();
                qu2.offer(tmp);
            }

        }
        return tmp;
    }

    public int top() {
        int tmp=0;

        if(qu1.isEmpty()){
            while(!qu2.isEmpty()){
           tmp=qu2.poll();
                qu1.offer(tmp);
            }

        }
        if(qu2.isEmpty()){
            while(!qu1.isEmpty()){
            tmp=qu1.poll();
                qu2.offer(tmp);
            }

        }
        return tmp;
    }

    public boolean empty() {
        return false;
    }

    public static void main(String[] args) {
        Queue<Integer> q = new LinkedList<>();

    }

}
